<template>
<div class="view-UserLogin">
    <el-form :model="formInline" :rules="rules" ref="ruleForm" class="demo-form-inline">
        <el-form-item label="用户名" prop="userId">
            <el-input v-model="formInline.userId" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="formInline.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>
</div>
</template>

<script>
// @ is an alias to /src
import { post, get, request } from '@/common/service'

export default {
    name: 'UserLogin',
    components: {
    },
    mounted () {
    },
    data () {
        return {
            // 单个模板-是否编辑模式
            formInline: {
                userId: 'xbl1',
                password: '123',
            },
            rules: {
                userId: [
                    { required: true, message: '请输入用户名', trigger: 'change' },
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'change' },
                ],
            }
        }
    },
    methods: {
        onSubmit () {
            this.$refs["ruleForm"].validate((valid) => {
                if (valid) {
                    this.sendLogin();
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        sendLogin () {
            let data = {
                userId: this.formInline.userId,
                password: this.formInline.password,
            };
            post(this.Api('loginIn'), data, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }).then((res) => {
                if(res.status == this.statusCode.successCode) {
                    console.log('登录成功');
                    this.$router.push("/javaviews/UserList")
                }else {
                    this.$message.error('登录失败');
                }
            });
        }
    }
}
</script>

<style scoped lang="scss">
.view-UserLogin{ padding: 40px 100px; }
</style>
